package is.glif.fenius.translators.example.db;

import is.glif.fenius.translators.example.bean.ExamplePersistentReservation;

import java.util.List;

import org.hibernate.Session;

/**
 * a simple DAO
 * @author haniotak
 *
 */
public class ExamplePersistentReservationDAO {
    public void create(List<ExamplePersistentReservation> listResvs) { 

        Session session = HibernateSessionUtil.getSessionfactory().openSession(); 
        session.getTransaction().begin(); 
    
        for (ExamplePersistentReservation resv : listResvs) { 
            System.out.println("saving: "+resv.getResvId());
            session.save(resv);
        } 
        session.getTransaction().commit(); 
    } 
    
    @SuppressWarnings("unchecked")
    public List<ExamplePersistentReservation> findAll() { 
        Session session = HibernateSessionUtil.getSessionfactory().openSession(); 
        List<ExamplePersistentReservation> list = (List<ExamplePersistentReservation>) session.createQuery("From ExamplePersistentReservation").list(); 
        
        return list;
    }
    
}
